//
//  XKLVideoAndVoiceVIew.m
//  GuiZiShouDuanZi
//
//  Created by xmg on 16/5/5.
//  Copyright © 2016年 xiao_kl. All rights reserved.
//

#import "XKLVideoAndVoiceVIew.h"
#import "XKLEessenceItem.h"
#import <UIImageView+WebCache.h>
#import "XKLShowPictureViewController.h"

@interface XKLVideoAndVoiceVIew()


@property (weak, nonatomic) IBOutlet UIImageView *VideoAndVoiceImage;
@property (weak, nonatomic) IBOutlet UIButton *voiceBut;
@property (weak, nonatomic) IBOutlet UILabel *playCount;
@property (weak, nonatomic) IBOutlet UILabel *playLenght;
@property (weak, nonatomic) IBOutlet UIButton *vifeoBut;

@end

@implementation XKLVideoAndVoiceVIew

+(instancetype)videoAndVoice{
    return [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self) owner:nil options:nil] lastObject];
}

-(void)awakeFromNib{
    self.autoresizingMask = UIViewAutoresizingNone;
    
   
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGes:)];
    [self.VideoAndVoiceImage addGestureRecognizer:tap];
}
//手势
-(void)tapGes:(UITapGestureRecognizer *)tap{
    
    XKLShowPictureViewController *showPicture = [[XKLShowPictureViewController alloc] init];
     showPicture.item = _item;
    [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:showPicture animated:YES completion:nil];
    
}

-(void)setItem:(XKLEessenceItem *)item{
    _item = item;
    
    [self.VideoAndVoiceImage sd_setImageWithURL:[NSURL URLWithString:item.image1]];
    
    self.playCount.text = [NSString stringWithFormat:@"播放%ld次",item.playfcount];
    //不同类型显示不一样的按钮
    if (item.type == kXKLTopicTypeVideo) {
        self.voiceBut.hidden = YES;
        self.vifeoBut.hidden = NO;
        NSInteger min = item.videotime / 60;
        NSInteger s = item.videotime % 60;
        self.playLenght.text = [NSString stringWithFormat:@"%02ld:%02ld",min,s];
    }else if(item.type == kXKLTopicTypeVoice){
        self.voiceBut.hidden = NO;
        self.vifeoBut.hidden = YES;
        NSInteger min = item.voicetime / 60;
        NSInteger s = item.voicetime % 60;
        self.playLenght.text = [NSString stringWithFormat:@"%02ld:%02ld",min,s];
    }
    
}

@end
